package com.koron.css2.workflow;

import com.koron.css2.ApplicationConfig;
import com.koron.css2.ServerInterface;
import com.koron.css2.common.utils.HttpUtils;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.css2.workflow.bean.OverdueDelayQuery;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.HashMap;
import java.util.Map;

public class OverdueDelay implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            OverdueDelayQuery overdueDelayQuery = JsonUtils.objectToPojo(req.getData(),OverdueDelayQuery.class);
            Map<String,String> map = new HashMap<>();
            map.put("processInstanceId",overdueDelayQuery.getProcessInstanceId());
            map.put("overdueTime",overdueDelayQuery.getOverdueTime());
            String url = ApplicationConfig.workflowUrl + "/process/overdue/delay.htm";
            String data = HttpUtils.sendGetForm(url,map);
            MessageBean message = JsonUtils.jsonToPojo(data, MessageBean.class);
            if (message.getCode() != Constant.MESSAGE_INT_SUCCESS){
                return MessageBean.create(Constant.MESSAGE_INT_FAIL,"延期失败",null);
            }
            return MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"延期成功",null);
        } catch (Exception e) {
            logger.error("延期失败",e);
        }
        return MessageBean.create(Constant.MESSAGE_INT_FAIL,"延期失败",null);
    }
}
